package org.example.iris.controller;

import org.example.iris.entity.InterviewSchedule;
import org.example.iris.service.InterviewScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/interviews")
public class InterviewScheduleController {

    @Autowired
    private InterviewScheduleService interviewScheduleService;

    // 安排面试
    @PostMapping("/arrange")
    public String arrangeInterview(@RequestParam int studentId,
                                   @RequestParam int companyId,
                                   @RequestParam String date,
                                   @RequestParam String time,
                                   @RequestParam String location,
                                   @RequestParam String result) {
        int resultStatus = interviewScheduleService.arrangeInterview(studentId, companyId, date, time, location, result);
        if (resultStatus > 0) {
            return "面试安排成功";
        } else {
            return "面试安排失败";
        }
    }

    // 获取学生的面试安排
    @GetMapping("/student/{studentId}")
    public List<InterviewSchedule> getStudentInterviewSchedules(@PathVariable int studentId) {
        return interviewScheduleService.getStudentInterviewSchedules(studentId);
    }

    // 获取公司面试安排
    @GetMapping("/company/{companyId}")
    public List<InterviewSchedule> getCompanyInterviewSchedules(@PathVariable int companyId) {
        return interviewScheduleService.getCompanyInterviewSchedules(companyId);
    }

    // 修改面试结果
    @PutMapping("/result/{interviewId}")
    public String modifyInterviewResult(@PathVariable int interviewId, @RequestParam String result) {
        int updateResult = interviewScheduleService.modifyInterviewResult(interviewId, result);
        if (updateResult > 0) {
            return "面试结果更新成功";
        } else {
            return "面试结果更新失败";
        }
    }

    // 删除面试安排
    @DeleteMapping("/{interviewId}")
    public String deleteInterviewSchedule(@PathVariable int interviewId) {
        int result = interviewScheduleService.removeInterviewSchedule(interviewId);
        if (result > 0) {
            return "面试安排删除成功";
        } else {
            return "面试安排删除失败";
        }
    }
}

